<script>
    function Add_product_type() {
	window.location.href = "?modul=products&action=add_products_type";
    }
</script>

<?php

function V_Products_Type($arrayData) { ?>
    <h3>Danh sách nhóm sản phẩm</h3>
    <p style="float: right"><input type="button" value="Thêm mới" onclick="Add_product_type();" /></p>
    <table width="950px" cellpadding="5" border="1">
	<?
	if (!empty($arrayData)) {
	    ?>
	    <tr style="background-color: #99CCFF">
		<th>Tên loại</th>
		<th>Ghi chú</th>
		<th width="40px">Sửa</th>
		<th width="40px">Xóa</th>
	    </tr>
	    <?
	    products_type(0, 0);
	} else {
	    echo "<tr><td colspan='3'>Khong co loai san pham nao</td></tr>";
	}
	?>

    </table>
    <?
}

function products_type($parent_id, $level) {
    global $db;
    $objProducts = new MD_Products($db);
    $where = " type_parent = '$parent_id'";
    $order = "";
    $limit = "";
    $array = $objProducts->get_product_type_by_Where($where, $order, $limit);
    foreach ($array as $value) {
	$id = $value['id'];
	?>
	<tr>
	    <td>
		<a class='memu_left_div_admin' href='?modul=products&action=List&parent_id=<?= $id ?>'>
		    <?= str_repeat('- - ', $level) . $value['type_name'] ?>
		</a>
	    </td>
	    <td>
		<a class='memu_left_div_admin'>
		    <?=$value['type_note'] ?>
		</a>
	    </td>
	    <td>
		<a href='?modul=products&action=Edit_type&id=<?= $id ?>'>Sửa</a>
	    </td>
	    <td>
		<a onclick="return confirm('Bạn có chắc chắn muốn xóa không?');"  href='?modul=products&action=Delete_type&id=<?= $id ?>'>Xóa</a>
	    </td>
	</tr>
	<?
	echo "";
	products_type($id, $level + 1);
    }
}
?>
